<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>密码系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

    <script>
        function page(){
            $.get({
                url:"${pageContext.request.contextPath}/Pwd/getPwdNum",
                success:function (data){
                    var content = document.getElementById("content");
                    content.insertAdjacentHTML("afterbegin","<li class='disabled'><a href='#' aria-label='Previous'><span aria-hidden='true'>&laquo;</span></a></li>");
                    for (let i = 0; i < data/10; i++) {
                        var li = document.createElement("li");
                        var a = document.createElement("a");
                        a.setAttribute("href","${pageContext.request.contextPath}/Pwd/getPwdPage?startIndex=" + (i+1));
                        a.insertAdjacentHTML("beforeend",(i+1));
                        li.appendChild(a);
                        content.appendChild(li);
                    }
                    content.insertAdjacentHTML("beforeend","<li class='disabled'><a href='#' aria-label='Next'><span aria-hidden='true'>&raquo;</span></a></li>");
                }
            });
        }
    </script>
</head>
<body onload="page()">

<div class="container">
    <div class="page-header">
        <h2>密码列表</h2>
    </div>

    <ul class="nav nav-pills">
        <li role="presentation">
            <form role="form" class="form-inline" method="get" action="${pageContext.request.contextPath}/Pwd/toAddPwd">
                <button type="submit" class="btn btn-primary">增加账户</button>
            </form>
        </li>
        <li>
            <form role="form" class="form-inline" method="get" action="${pageContext.request.contextPath}/Pwd/getPwdList">
                <button type="submit" class="btn btn-primary">查找全部</button>
            </form>
        </li>
        <li role="presentation">
            <form role="form" class="form-inline" method="get" action="${pageContext.request.contextPath}/Pwd/selectPwd">
            <input type="text" class="form-control" name="accountName"
                   placeholder="请输入账户信息">
            <button type="submit" class="btn btn-primary">查找</button>
        </form>
        </li>
        <li>
            <form role="form" class="form-inline" method="get" action="${pageContext.request.contextPath}/logout">
                <button type="submit" class="btn btn-primary">退出登录</button>
            </form>
        </li>
    </ul>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>序号</th>
            <th>账户信息</th>
            <th>账号</th>
            <th>密码</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="PwdList" items="${requestScope.get('list')}">
            <tr>
                <td>${PwdList.getId()}</td>
                <td>${PwdList.getAccountName()}</td>
                <td>${PwdList.getAccount()}</td>
                <td>${PwdList.getPassword()}</td>
                <td>${PwdList.getCreateTime()}</td>
                <td>${PwdList.getUpdateTime()}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/Pwd/toUpdatePwd?id=${PwdList.getId()}">修改</a>
                    <a href="${pageContext.request.contextPath}/Pwd/deletePwd?id=${PwdList.getId()}">删除</a>
                </td>

            </tr>
        </c:forEach>
        </tbody>
    </table>
    <hr>

    <nav aria-label="Page navigation">
        <ul class="pagination" id="content">
        </ul>
    </nav>

</div>

</body>
</html>
